class JQCategoryProductListService extends global.JQService {
	
    async do_action(){
		
		if(!this.conn)console.log('do_action::conn error');
		let data_obj = this.req_obj.data_obj;
		let inst = global.JQTableIF.instance('menu_table',this.conn);
	    let inst_b = global.JQTableIF.instance('cp_table',this.conn);
		;
	   
	   /*
	   'cp_id',// int(4) ai pk
	   'cp_number',// varchar(20) 
	   'cp_name',// varchar(64) 
	   'cp_picture',// varchar(255) 
	   'cp_price',// double(20,2) 
	   'cp_remark',// varchar(1024) 
	   'cp_state',// int(4) 
	   'cp_total',// int(20) 
	   'cp_count',// int(20) 
	   'cp_dprice',// double(3,2) 
	   'cp_flag',// int(11) 
	   'menu_id',// int(11) 
	   'cp_type',// int(11) 
	   'sort',// int(11) 
	   'create_time',// datetime 
	   'cp_ids',// varchar(255) 
	   'vip_price',// double(10,2) 
	   'vip_price_two',// double(10,2) 
	   'vip_price_three',// double(10,2) 
	   'cp_reserve',// int(11) 
	   'cp_thumbnail',// varchar(255) 
	   'cp_spell',// varchar(255) 
	   'cp_lowsell',// int(11) 
	   'is_discount',// int(2) 
	   'cp_subs',// varchar(1024) 
	   'cp_temp',// int(11) 
	   'cp_no',// int(5) 
	   'cp_belong_group',// int(1) 
	   'cp_option_subs',// varchar(10240) 
	   'cp_fixedsubs',// int(11) 
	   'cp_choose',// int(11) 
	   'cp_takeout_price',// double(10,2) 
	   'cp_recommend',// int(11) 
	   'cp_remark_type',// int(4) 
	   'cp_html',// longtext 
	   'cp_online',// int(11) 
	   'cp_disabled',// int(1) 
	   'ex_no',// int(11) 
	   'cp_limited',// int(11)
	   */
	   
	   /*
	   'menu_number','menu_name','m_picture','u_id','sort  menu_sort'
	   
	   'menu_id',// int(4) ai pk
	   'menu_number',// varchar(120) 
	   'menu_name',// varchar(64) 
	   'm_picture',// varchar(255) 
	   'u_id',// int(11) 
	   'sort',// int(11) 
	   'menu_reserve',// int(11) 
	   'menu_no',// int(5) 
	   'menu_pname',// varchar(64) 
	   'menu_online',// int(11) 
	   'ex_no',// int(11)
	   
	   */
	   
	   
		let wrap = {};
		console.log('do_action 11111');

		let menu_id = data_obj?data_obj.menu_id:null;
		let params_a=super._addUserParams();;
	//	params_a= super._addParams(['service_state!=',2],params_a);
		if(menu_id){
			params_a=this._addParams(['menu_id =',search],params_a);
		}
		console.log('do_action 22222');
		let alias_keys=null 
		let a_keys=null;
		let alias_a_keys=['menu_number','menu_name','m_picture','u_id','sort   menu_sort'];
		let b_table='cp';				
		let b_keys=inst_b.keys;;
		let alias_b_keys = inst_b.keys;
		let params_b =null;
		let joint='left join';
		let first= data_obj.first;
		let size = data_obj.size;	
		let on_a='menu_id';
		let on_b= 'menu_id';
		let params=null;
		let order_by='menu_sort desc, sort desc';
		let group_by =null;
		
		//async query2(alias_keys,alias_a_keys, a_keys,a_params, b_table,alias_b_keys,b_keys,b_params,joint,on_a,on_b,params, first,size,group_by,order_by,is_count){}//(alias_a_keys, a_keys,a_params,alias_b_keys, b_table,b_keys,b_params,joint,on_a,on_b,params, first,size,group_by,order_by,is_count){}
		let list = await inst.query2(alias_keys,alias_a_keys,a_keys,params_a,
			b_table,alias_b_keys,b_keys,params_b,joint,
		   on_a,on_b,params,first,size,group_by,order_by);
		
		// let count = await inst.count2(alias_keys,alias_a_keys,a_keys,params_a,
		// 	b_table,alias_b_keys,b_keys,params_b,joint,
		//    on_a,on_b,params,group_by,order_by);
		   
		//wrap.list=list;
		let aggret=[];
		let products=[];
		let last ={};
		let current={};
		if(list && list.length){
			current.menu_id=list[0].menu_id;
			current.menu_name=list[0].menu_name;
			
		}
		if(list){
			list.forEach((item)=>{
			
				if(current.menu_id != item.menu_id){
					if(products.length>0){
						current.products=products;
						
					}
					aggret.push(current);
					current={};
					current.menu_id=item.menu_id;
					current.menu_name=item.menu_name;
					products=[];
					console.log(1111);
				}
				if(!item.cp_id){
					console.log('cp_id is null')
				}else{
					let product={};
					product.cp_id=item.cp_id;
					product.cp_name=item.cp_name;
					product.cp_picture=item.cp_picture;
					product.cp_price=item.cp_price;
					product.vip_price=item.vip_price;
					product.menu_id=item.menu_id;
					products.push(product);
				}
				
			})
		}
		
		//the last item into array
		if(list && list.length){
			if(products.length>0)current.products=products;
			aggret.push(current);
			
		}
	
		// wrap.total=count;
		console.log(JSON.stringify(aggret));
		wrap.list=aggret;
		return wrap;			
	}

}
module.exports = JQCategoryProductListService;

